<?php
namespace app\api\model;
use think\Model;
use think\Db;
class Cancel extends Model{
    public function selectWhere($where){
      $res=Db::query("SELECT
	o.order_time
FROM
	gx_appointment_gym gy,
	gx_order o
WHERE
	o.id = gy.order_id
AND gy.user_id = ?
AND gy.place_id=?
AND gy.appoint_time = ?
AND gy.riqi = ?
AND o.`status` = 1",array($where['user_id'],$where['place_id'],$where['appoint_time'],$where['riqi']));
      if(!empty($res)){
          return $res;
      }else{
          return 0;
      }
    }
    public function update_status($id){
     $res= Db::name('order')
      ->where(array('id'=>$id))
      ->update(array('status'=>-1));
     if(!empty($res)){
         return $res;
     }else{
         return 0;
     }
    }
    public function update_status2($where){
        $r= Db::execute("UPDATE gx_order o
SET o.`status` =10
WHERE
	o.id = (
		SELECT
			gy.order_id
		FROM
			gx_appointment_gym gy
		WHERE
			gy.user_id = :user_id
		AND gy.place_id = :place_id
		AND gy.appoint_time = :appoint_time
		AND gy.riqi = :riqi
	)
	)",$where);
        if(!empty($r)){
            return $r;
        }else{
            return 0;
        }
    }
    //更新我的账户余额 违约更新
    public function update_my_account($user_id,$dongjie){
       
$res=Db::name('my_account')
    ->where('user_id',$user_id)
    ->setDec('dongjie',$dongjie);;
   
  if($res){
      return $res;
  }else {
      return 0;
  }
    }
    //取消更新
    public function update_my_account2($user_id,$dongjie){
       $res= Db::name('my_account')
        ->where('user_id',$user_id)
        ->update([
            'dongejie' => ['exp','dongjie'-$dongjie],
            'account_balance'=>['exp','account_balance'+$dongjie]
        ]);
        if($res){
            return $res;
        }else {
            return 0;
        }
    }
    public function selectOrderId($where){
       $res= Db::name('appointment_gym')
        ->field('order_id')
        ->where($where)
        ->find();
       if($res){
           return $res['order_id'];
       }else{
           return 0;
       }
    }
}